<%--
  Created by IntelliJ IDEA.
  User: 20493
  Date: 2023/10/29
  Time: 15:22
  To change this template use File | Settings | File Templates.
--%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8" import="com.dao.*,com.bean.*" %>
<%
    request.setCharacterEncoding("utf-8");
%>

<jsp:useBean id="stu_DAO" class="com.dao.studentDAO"></jsp:useBean>
<jsp:useBean id="student" class="com.bean.Student"></jsp:useBean>
<jsp:setProperty property="*" name="student"/>
<%

    int id=0;
    String action = request.getParameter("action");
    boolean result = false;
    if (request.getParameter("id") != null)
        id = Integer.parseInt(request.getParameter("id"));
    String msg="";


    if(action.equals("edit")) {
        student = stu_DAO.getById(id);
        request.setAttribute("student", student);
        request.getRequestDispatcher("edit.jsp").forward(request, response);
    }
    if(action.equals("delete")){
        result= stu_DAO.delete(id);
        if (result==true)
            msg="学生删除成功!";
        else
            msg="学生删除失败";
        session.setAttribute("msg",msg);
        response.sendRedirect("Result.jsp");
        return;
    }
    if(action.equals("add")){

        result = stu_DAO.addStu(student);
        if(result == true)
            msg = "学生 添 加 成 功 !";
        else
            msg = " 学生 添 加 失 败 !";
        session.setAttribute("msg", msg);
        response.sendRedirect("Result.jsp");
        return;


        }





%>

<html>
<head>
    <title>Title</title>
</head>
<body>

</body>
</html>
